import type { UserVO } from "@/index";
import { defineStore } from "pinia";
import { ref } from "vue";

export const useUserStore = defineStore("user", () => {
  const token = ref<string | null>(null)

  const setToken = (value: string) => token.value = value

  const userInfo = ref<UserVO | null>(null)

  /**设置用户信息 */
  const setUserInfo = (value: UserVO) => {
    userInfo.value = {
      ...userInfo.value,
      ...value
    }
  }

  const logout = () => {
    userInfo.value = null
    setToken('')
  }
  return {
    token,
    userInfo,
    setToken,
    setUserInfo,
    logout
  }
}, {
  persist: true
}) 